/**
 * 
 */
package poc.android.explistview;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import poc.android.util.POCApplication;
import poc.android.weather.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 *
 * @author Jason
 * created at: Oct 14, 2011
 */
public class NoMoreExpandableListViewActivity extends Activity {
	/*
	 * state(s) to be preserved for activity recovering...
	 */
	protected static final String STATE_BRANDS="STATE_BRANDS";
	protected static final String STATE_BUTTON_TEXT="STATE_BUTTON_TEXT";
	protected static final String NO_MORE_EXP_BRANDS_LIST="NO_MORE_EXP_BRANDS_LIST";
	/**
	 * intent for calling the Brands selection Activity
	 */
	protected static final String INTENT_ACTION_NO_MORE_EXP_BRANDS_PAGE_SHOW="INTENT_ACTION_NO_MORE_EXP_BRANDS_PAGE_SHOW";
	
	static final String TAG="NoMoreExpandableListViewActivity";
	
	POCApplication mApplication;
	boolean firstLoad=true;
	
	Button mBtnTest;
	TextView mTxtBrands;
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Map<String, Object> aMap=null;
		List<String> aBrandsList=new ArrayList<String>();
		
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.no_more_exp_activity);
		
		this.mApplication=(POCApplication) this.getApplication();
		aMap=this.mApplication.getApplicationProperty(POCApplication.APP_NO_MORE_EXP);
		/*
		 * setup any other related List or properties for this module
		 */
		aBrandsList.add("01-BRA001");
		aBrandsList.add("02-Lust");
		aBrandsList.add("45-Goo");
		aBrandsList.add("99-Ilectra");
		for(int i=16; i<22; i++) {
			aBrandsList.add(i+"-Brand"+i);
		}
		aMap.put(NO_MORE_EXP_BRANDS_LIST, aBrandsList);
		
		this.setupWidgets();
	}
	
	/**
	 * method setting up the widgets
	 */
	private void setupWidgets() {
		this.mBtnTest=(Button) this.findViewById(R.id.btnNoMoreExpTest);
		this.mBtnTest.setOnClickListener(new Button.OnClickListener(){
			/**
			 * onClick event handler
			 */
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
			}}
		);
		this.mTxtBrands=(TextView) this.findViewById(R.id.txtBrands);
		this.mTxtBrands.setOnClickListener(new View.OnClickListener() {
			/**
			 * onClick event handler
			 */
			public void onClick(View v) {
				Intent aIntent=new Intent(INTENT_ACTION_NO_MORE_EXP_BRANDS_PAGE_SHOW);
				startActivity(aIntent);
			}}
		);
	}

	/**
	 * {@inheritDoc}
	 * @see android.app.Activity#onPause()
	 */
	@Override
	protected void onPause() {
		Map<String, Object> aMap=this.mApplication.getApplicationProperty(POCApplication.APP_NO_MORE_EXP);
		/*
		 * save the screen states to the POCApplication
		 */
		if (aMap!=null) {
			aMap.put(STATE_BRANDS, this.mTxtBrands.getText().toString());
			aMap.put(STATE_BUTTON_TEXT, this.mBtnTest.getText().toString());
		}
		super.onPause();
		Log.w(TAG, "inside onPause; when the activity lost focus");
	}

	/**
	 * {@inheritDoc}
	 * @see android.app.Activity#onResume()
	 */
	@Override
	protected void onResume() {
		Map<String, Object> aMap=null;
		
		super.onResume();
		/*
		 * update the screen states to the POCApplication
		 */
		if (!this.firstLoad) {
			aMap=this.mApplication.getApplicationProperty(POCApplication.APP_NO_MORE_EXP);
			this.mTxtBrands.setText((String) aMap.get(STATE_BRANDS));
			this.mBtnTest.setText((String) aMap.get(STATE_BUTTON_TEXT));
			
		} else {
			this.firstLoad=false;
		}
		Log.w(TAG, "inside onResume; when the activity back to life: "+this.firstLoad);
	}

}
